<%@ page language="java" import="java.util.List,cn.com.wxd.entity.website.ArticleInfo" pageEncoding="utf-8" %>
<%@page import="cn.com.wxd.common.CharUtil" %>
<%@page import="cn.com.wxd.common.PageInfo" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    PageInfo pageInfo = (PageInfo) request.getAttribute("page");
    String skw = (String) request.getSession().getAttribute("admin_searchKeyWord");
    String skt = (String) request.getSession().getAttribute("admin_searchType");
%>
<script type="text/javascript">
    //预览查看文章内容
    function CheckContent(id) {
        $.ajax({
            type: "get",
            url: "admin/website/article/fetchArticle/" + id,
            data: {},
            success: function (result) {
                if (result.success) {
                    parentLayer.open({
                        type: 1,
                        area: ['1125px', '600px'], //宽高
                        content: result.data.content
                    });
//                    var contentwin = open("", "contentwin", "left=130,top=120,width=1100," +
//                        "height=660,status=no,resizable=yes,scrollable=yes,menubar=" +
//                        "yes,toolbar=no,");
//                    contentwin.document.open();
//                    contentwin.document.write(result.data.content);
                }
            }
        });
    }
    //删除文章
    function deleteArticle() {
        var ids = "";
        var box = document.getElementsByName("selectRow");
        for (var i = 0; i < box.length; i++) {
            if (box[i].checked) { //判断复选框是否选中
                ids = ids + box[i].value + "/";//使用“/”分隔开
            }
        }
        if (ids == "") {
            layer.alert('请勾选要删除的文章！');
        } else {
            layer.confirm('你确定要删除吗?', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                //显示动态遮挡页面
                showLoading();
                $.ajax({
                    type: "post",
                    url: "admin/website/article/batchDeleteArticle",
                    data: {"ids": ids},
                    success: function (result) {
                        loadingClose();
                        if (result.success) {
                            <%
                                if(skw!=null&&(!skw.trim().equals(""))){
                            %>
                            submitSearch("", "1");
                            <%
                                }else{
                            %>
                            FListajax("<%=request.getAttribute("caid")%>", "<%=pageInfo.getPageIndex()%>");
                            <%
                                }
                            %>

                            //删除成功
                            OutMessageBox("删除成功", 3000);
                        } else {
                            //删除失败
                            OutMessageBox("删除失败", 3000);
                        }
                    }
                });
            }, function () {
                OutMessageBox("取消删除", 3000);
            });
        }
    }
    //弹出选择栏目模态框
    function showModal(type) {
        var ids = "";
        var box = document.getElementsByName("selectRow");
        $("#WorkType").val(type);
        for (var i = 0; i < box.length; i++) {
            if (box[i].checked) { //判断复选框是否选中
                ids = ids + box[i].value + "/";//使用“/”分隔开
            }
        }
        if (ids == "") {
            layer.alert('请勾选文章！');
        } else {
            //保存ids
            $("#ArticieIds").val(ids);
            $("#cataListModal").modal({//调用模态框弹出选择栏目
                keyboard: false
            });
        }
    }
    //实现全选功能
    function cli(Obj) {
        var collid = document.getElementById("allSelect");
        var coll = document.getElementsByName(Obj);
        if (collid.checked) {
            for (var i = 0; i < coll.length; i++)
                coll[i].checked = true;
        } else {
            for (var i = 0; i < coll.length; i++)
                coll[i].checked = false;
        }
    }
    function reBuildIndex() {
        layer.confirm('你确定要重建全文吗？建立过程缓慢，请耐心等待！', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            //显示加载动态图标
            showLoading();
            $.ajax({
                type: "get",
                url: "admin/website/article/reBuildArticleIndex",
                data: {},
                success: function (result) {
                    loadingClose();
                    if (result.success) {
                        //重建成功!");
                        OutMessageBox("重建成功!", 3000);
                    } else {
                        //重建失败！请稍后再试");
                        OutMessageBox("重建失败，请稍后再试!", 3000);
                    }
                }
            });
        }, function () {
            layer.msg('取消建立索引!');
        });

    }
    function OrderAjax(newid, oldid) {
        //显示加载动态图标
        showLoading();
        $.ajax({
            type: "get",
            url: "admin/website/article/articleSorting", ////////排序方法
            data: {"newOrdId": newid, "oldOrdId": oldid},
            success: function (result) {
                loadingClose();
                if (result.success) {
                    FListajax("<%=request.getAttribute("caid")%>", "<%=pageInfo.getPageIndex()%>");	 //移动成功！刷新
                } else {
                    OutMessageBox("排序失败，未知原因!", 3000);
                    return;
                }
            }
        });
    }
</script>
<div>
    <div>
        <div id="topnav" style="background-color: #E3E7EA;"><span
                style="color:#40919E;font-size:12px;margin-left: 5px">${cataNav}</span></div>
        <div style="margin-top:10px;margin-left:20px;margin-bottom:5px">
            <%
                if (skw == null || skw.trim().equals("")) {
            %>
            <a
                    href="admin/website/article/addArticle?caid=${caid}">
                <button class="btn btn-success btn-xs">采编新文章</button>
            </a>&nbsp;
            <%
                }
            %>

            <button class="btn btn-warning btn-xs" onclick="deleteArticle()">删除</button>
            &nbsp;&nbsp;
            <div class="btn-group">
                <button type="button" class="btn btn-info btn-xs dropdown-toggle"
                        data-toggle="dropdown">
                    高级功能 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li><input type="hidden" value="" id="ArticieIds"/><a href="javascript:showModal('move')">移动</a>
                    </li>
                    <li><input type="hidden" value="" id="WorkType"/><a href="javascript:showModal('clone')">克隆</a></li>
                    <li class="divider"></li>
                    <li><a href="javascript:reBuildIndex()">重建全文索引</a></li>
                </ul>
            </div>
            <div id="searchDIV" style="float: right;width: 50%;margin-bottom: 5px;margin-right: 15px;">
                <form action="">
                    <script type="text/javascript">
                        <%
                            if(skw!=null&&(!skw.trim().equals(""))){
                                %>
                        $("#searchKeyWord").val("<%=skw%>");
                        $("#searchType").val("<%=request.getSession().getAttribute("searchType")%>");
                        <%
                    }
                %>
                        $("#searchType").val("title");
                        function chanageType(type, typeName) {
                            $("#searchType").val(type);
                            $("#searchTypeP").text(typeName);
                        }
                        function submitSearch(args, pageInd) {
                            var searchTypeStr = $("#searchType").val();
                            var searchKeyWordStr = $("#searchKeyWord").val();
                            var regu = "^[ ]+$";
                            var re = new RegExp(regu);

                            if (searchKeyWordStr == null || searchKeyWordStr == undefined || searchKeyWordStr == '' || (re.test(searchKeyWordStr))) {
                                jAlert('请输入关键字！', '提示');
                            } else {
                                SearchAjax(searchTypeStr, searchKeyWordStr, pageInd);
                            }
                        }
                        function SearchAjax(searchTy, searchKeyW, pageIn) {
                            //显示动画
                            $("#right").append("<div id=\"zhedang\"><div id=\"loader\" class=\"loader-inner line-spin-fade-loader\"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>");
                            $.ajax({  //ajax操作搜索
                                type: "post",
                                url: "admin/website/article/searchArticle",   //页容量为24
                                data: {
                                    "searchType": searchTy,
                                    "searchKeyWord": searchKeyW,
                                    "pageSize": 24,
                                    "pageIndex": pageIn
                                },
                                success: function (result) {
                                    if (result != null && result != "") {
                                        $("#zhedang").remove();
                                        $("#right").html(result);
                                    } else {
                                        $("#zhedang").remove();
                                        //重建失败！请稍后再试");
                                        OutMessageBox("搜索失败，请稍后再试!", "no", "3000");
                                    }
                                },
                                error: function () {
                                    $("#zhedang").remove();
                                    OutMessageBox("搜索失败，请稍后再试!", "no", "3000");
                                }
                            });
                        }
                    </script>
                    <div class="input-group input-group-sm">
                        <div class="input-group-btn">
                            <input id="searchType" type="hidden" name="searchType" value="title">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                    aria-haspopup="true" aria-expanded="false"><span id="searchTypeP">标题 </span><span
                                    class="caret"></span></button>
                            <ul class="dropdown-menu" style="min-width: 80px;">
                                <li><a href="javascript:chanageType('title','标题 ')">标题</a></li>
                                <li><a href="javascript:chanageType('author','作者 ')">作者</a></li>
                                <li><a href="javascript:chanageType('keyWord','关键字 ')">关键字</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="javascript:chanageType('content','内容索引 ')">全文搜索</a></li>
                            </ul>
                        </div><!-- /btn-group -->
                        <input id="searchKeyWord" name="searchKeyWord" placeholder="请输入关键字" type="text"
                               class="form-control"/>
                        <span class="input-group-btn">
					  	<input type="button" class="btn btn-default" value="搜索！" onclick="submitSearch('',1)"/>
					  </span>
                    </div>
                </form>
            </div>
        </div>
        <form action="">
            <table width="97%" align="center" border="1" cellspacing="0"
                   cellpadding="0">
                <thead>
                <tr style="background-color:#41a7c5;">
                    <th style="text-align:center;"><input type="checkbox" id="allSelect"
                                                          onclick="cli('selectRow');" value=""/>
                    </th>
                    <th style="text-align:center;">ID</th>
                    <th style="text-align:center;">标题</th>
                    <th style="text-align:center;">类型</th>
                    <th style="text-align:center;">状态</th>
                    <th style="text-align:center;">作者</th>
                    <th style="text-align:center;">时间</th>
                    <th style="text-align:center;">点击量</th>
                    <th style="text-align:center;">排序</th>
                    <th style="text-align:center;">操作</th>
                </tr>
                </thead>
                <tbody style="background-color:#F7F7F9;word-break:break-all;">
                <%
                    List<ArticleInfo> lists = (List<ArticleInfo>) request.getAttribute("aritcleList");
                    if (lists != null && lists.size() > 0) {  //排序
                        for (int i = 0; i < lists.size(); i++) {
                            long lastOrderId;  //设置排序的上一个位置
                            long nextOrderId;  //设置排序的下一个位置
                            if (i == 0) {
                                lastOrderId = lists.get(i).getOrderId();
                                if (lists.size() - 1 == i) {
                                    nextOrderId = lists.get(i).getOrderId();
                                } else {
                                    nextOrderId = lists.get(i + 1).getOrderId();
                                }
                            } else {
                                lastOrderId = lists.get(i - 1).getOrderId();
                                if (lists.size() - 1 == i) {
                                    nextOrderId = lists.get(i).getOrderId();
                                } else {
                                    nextOrderId = lists.get(i + 1).getOrderId();
                                }
                            }
                %>
                <tr id="datarow" onmouseover="this.style.backgroundColor='#BCD8E0'"
                    onmouseout="this.style.backgroundColor='#F7F7F9'">
                    <td width="30px" style="text-align:center;"><input
                            type="checkbox" id="selectRow" name="selectRow"
                            value="<%=lists.get(i).getId() %>"/>
                    </td>
                    <td width="40px" style="text-align:center;"><%=lists.get(i).getId() %>
                    </td>
                    <td width="180px" title="<%=lists.get(i).getTitle()%>">
                        <%
                            if (lists.get(i).getIsHotPaper() != null && lists.get(i).getIsHotPaper().trim()
                                    .equals("Y")) {
                        %>
                        <i class="glyphicon glyphicon-fire"></i>
                        <%
                            }
                        %>
                        <%=CharUtil.subStringByte(lists.get(i).getTitle(), 20) %>
                    </td>
                    <td width="60px" style="text-align:center;">
                        <%
                            switch (lists.get(i).getType().charAt(0)) {//'T':'文本','P':'图片','V':'视屏','F':'FLASH','L':'巨幕'
                                case 'T':
                        %> 文本 <%
                            break;
                        case 'P':
                    %> 图片 <%
                            break;
                        case 'V':
                    %> 视屏 <%
                            break;
                        case 'F':
                    %> FLASH <%
                            break;
                        case 'L':
                    %> 巨幕 <%
                            break;
                        default:
                    %> 其他 <%
                                break;
                        }
                    %>
                    </td>
                    <td width="75px" style="text-align:center;">
                        <%
                            switch (lists.get(i).getState().charAt(0)) {
                                case 'P':
                        %> 已发布 <%
                            break;
                        case 'A':
                    %> 待审核 <%
                            break;
                        default:
                    %> 未知 <%
                        }
                    %>
                    </td>
                    <td width="95px" style="text-align:center;"><%=CharUtil
                            .subStringByte(lists.get(i).getAuthor(), 8) %>
                    </td>
                    <td width="100px" style="text-align:center;"><%=CharUtil
                            .subStringByte(lists.get(i).getDateTime(), 10) %>
                    </td>
                    <td width="70px" style="text-align:center;"><%=lists.get(i).getArticleClick() %>
                    </td>
                    <td width="80px" style="text-align:center;">
                        <%
                            if (skw == null || skw.trim().equals("")) {
                        %>
                        <a href="#" onclick="OrderAjax('<%=lastOrderId %>','<%=lists.get(i).getOrderId() %>')"><span
                                class="glyphicon glyphicon-triangle-top" aria-hidden="true"></span></a>&nbsp;
                        <a href="#" onclick="OrderAjax('<%=nextOrderId%>','<%=lists.get(i).getOrderId() %>')"><span
                                class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span></a>
                        <%
                        } else {
                        %>
                        <span class="glyphicon glyphicon-triangle-top" aria-hidden="true"></span>&nbsp;
                        <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
                        <%
                            }
                        %>
                    </td>
                    <td width="135px" style="text-align:center;">&nbsp;&nbsp; <a
                            href="admin/website/article/updateArticle?id=<%=lists.get(i).getId()%>">修改</a>
                        &nbsp;&nbsp;&nbsp;
                        <a href='javascript:CheckContent("<%=lists.get(i).getId()%>")'>预览</a>
                    </td>
                </tr>

                <%
                    }
                } else {
                %>
                <tr height="40px">
                    <td colspan="10" align="center">
                        <span style="color:red;font-size:20px"><i style="color:blue;"
                                                                  class="glyphicon glyphicon-info-sign"></i>&nbsp;此栏目下没有文章！</span>
                    </td>
                </tr>
                <%
                    }
                %>
                </tbody>
            </table>
        </form>
    </div>
    <div id="paging" style="width:100%;bottom: 50px;position: absolute">
        <%
            if (skw != null && (!skw.trim().equals(""))) {
        %>
        <jsp:include page="/WEB-INF/views/component/pagecontrolOfjs.jsp">
            <jsp:param value="submitSearch" name="ajaxFunction"/>
        </jsp:include>
        <%
        } else {
        %>
        <jsp:include page="/WEB-INF/views/component/pagecontrolOfjs.jsp">
            <jsp:param value="FListajax" name="ajaxFunction"/>
        </jsp:include>
        <%
            }
        %>
    </div>
</div>



